<?php
namespace Home\Controller;

class ArticleController extends HomeController {
    
	/* 文档模型列表页 */
	public function lists($p = 1){
	    
	    $M_help=M('help');
	    $id=I('id');
	    $map=array();
	    $map['pid']=$id;
	    $p<=0 && $p=1;
	    $pagesize=10;
	    $offset=($p-1)*$pagesize;
	    
	    $list=$M_help->where($map)->limit($offset,$pagesize)->field('id,pid,title')->select();
	    $total=$M_help->where($map)->count();
	    
	    $this->assign('_list',$list);
	    $ptitle=get_table_field($id,'id','title','help');
	    $this->assign('ptitle',$ptitle);	    
	  
	    $this->assign('pid',$id);	  
	    
	    $__PAGE__ = new \Think\Page($total, $pagesize);
	    
	    $__PAGE__->lastSuffix = false;
	    $__PAGE__->rollPage = 6;
	    $__PAGE__->setConfig('prev', '<');
	    $__PAGE__->setConfig('next', '>');
	    $__PAGE__->setConfig('first', '<<');
	    $__PAGE__->setConfig('last', '<span>...</span>');
	    $__PAGE__->setConfig('header', '<span>共%TOTAL_PAGE%页</span>');
	    $__PAGE__->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %END% %DOWN_PAGE% %HEADER%');
	    
	    $this->assign('_page', $__PAGE__->show());
		$this->display('lists');
	}
	
	/* 文档模型详情页 */
	public function detail($id = 0, $p = 1){
	    $M_help=M('help');
	    $info=$M_help->find($id);	    
	    $map=array('pid'=>$id);
	    
	    $not_last_node=$M_help->where($map)->select();
	    //跳转到列表
	    if($not_last_node){
	        $this->lists();
	        exit;
	    }
	   
	    //显示详细
	    $pinfo=$M_help->field('id,title,pid')->find($info['pid']);	 
	    $ptitle=$pinfo['title'];
	    if((int)$pinfo['pid']==0){
	        $this->assign('pid',$info['id']);
	    }else{
	        $this->assign('pid',$pinfo['id']);
	    }
	    
	    $this->assign('info',$info);
	    
	    $this->assign('ptitle',$ptitle);
		$this->display('detail');
		
		
	}
}
?>